module Node.Stream.Helper.NdJson (
    parse,
    onJsonEither
) where

import Prelude

import Data.Argonaut (Json, jsonParser)
import Data.Either (Either)
import Effect (Effect)
import Node.Stream (Duplex, Readable)

foreign import parse ::Effect Duplex


foreign import onStringEitherImpl:: forall r . (String -> Either String Json) -> Readable r -> (Either String Json -> Effect Unit) -> Effect Unit

onJsonEither::forall r . Readable r -> (Either String Json -> Effect Unit) -> Effect Unit
onJsonEither = onStringEitherImpl jsonParser